<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> 								
	<head> 							
		<%@ include file="../jslib/jquerylib.jsp" %>
		 <link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/jqGrid/css/jqgrid.css"></link>
	    <script type="text/javascript" src="<%=request.getContextPath() %>/jslib/lhgdialog/lhgcore.lhgdialog.min.js?skin=mac"></script>
	        <script type='text/javascript' src="<%=request.getContextPath() %>/jslib/My97DatePicker/WdatePicker.js" defer="defer"></script>
        <link href="<%=request.getContextPath() %>/web/style/layout.css" type="text/css" rel="stylesheet"/>
        <link rel="stylesheet" href="<%=request.getContextPath() %>/jslib/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css"/>
        <script type="text/javascript" src="<%=request.getContextPath() %>/jslib/ztree/jquery.ztree.core-3.4.js"></script>
	       <!-- 删除结果信息返回 -->
	    	<c:if test="${requestScope.message!=null}">
				<script type="text/javascript">
	  	 		     alert('<c:out value="${requestScope.message}"></c:out>');
	  	 		     window.close();
	  			</script>
	        </c:if>
	 
	<script type="text/javascript">
	$(document).ready(function(){
				//高级搜索需要的js
				buttonStatus=1;
				$("#flip").click(function(){
					if(buttonStatus==1){
						$("#panel").slideToggle("slow");
						$("#flip").toggleClass("btnStatus2");
						buttonStatus=1;
					}
					else{
						$("#panel").slideUp("slow");
						$("#flip").toggleClass("btnStatus2");
					}
			 });
				 //高级搜索结束
	
					$("#gridTable").jqGrid({
						url:'<%=request.getContextPath() %>/eqAction!queryDataList.action',
						datatype: "json",
						height: 450,
						width: 710, 
						autowidth: true, 
						colNames:['序号','设备名称','设备编号','规格型号','出厂编号','合同编号','购进日期','预计使用年限（年）','已经使用时间（月）','货币类型','合同价格','税率(%)','汇率','原值（元）','原值（万元）','净值（万元）','折旧（万元）','状态','部门'],
						colModel:[
								{name:'ID',index:'ID', width:60, key:true, sorttype:"int",hidden:true,hidedlg:true}, 
								{name:'E_NAME',index:'E_NAME', width:100},								
								{name:'E_NO',index:'E_NO', width:100},
								{name:'E_GUGE',index:'E_GUGE', width:110},
								{name:'E_C_NO',index:'E_C_NO', width:110},
								{name:'E_HT_NO',index:'E_HT_NO', width:110},
								{name:'E_GJ_DATE',index:'E_GJ_DATE', width:50,hidden:true},
								{name:'E_YJSYNX',index:'E_YJSYNX', width:50,hidden:true},
								{name:'E_YJSYSJ',index:'E_YJSYSJ', width:110},
								{name:'E_HBLX',index:'E_HBLX', width:110},
								{name:'E_HTJG',index:'E_HTJG', width:110},
								{name:'c',index:'E_SHUILV', width:110},
								{name:'E_HUILV',index:'E_HUILV', width:50},
								{name:'E_YZHI',index:'E_YZHI', width:80,hidden:true},
								{name:'E_YZW',index:'E_YZW',width:110},
								{name:'E_JZW',index:'E_JZW', width:80},
								{name:'E_ZJW',index:'E_ZJW', width:110},
								{name:'STATE',index:'STATE', width:80},
								{name:'E_ORG_NAME',index:'E_ORG_NAME', width:110}
					],
					shrinkToFit:false,
					sortname:'ID',
					sortorder:'desc',
					viewrecords:true,
					multiselect: true, // 是否显示复选框
					multiboxonly : true, 
					//gridview: true,  //提升速度
					rownumbers: true,//显示行号
					rownumWidth: 30, //行号的宽度
					rowNum:15,
					rowList:[15,20,50,200,500],
					toolbar: [false,"top"],
					loadComplete: function() {
						var ids = jQuery("#gridTable").getDataIDs();
				        if(ids.length<20){
				        	 jQuery("#gridTable").jqGrid('setGridHeight',390); 
				        	 parent.document.getElementById("mainframe").height=670; 
				        }else{
				        	 jQuery("#gridTable").jqGrid('setGridHeight',ids.length*24); 
				        	 parent.document.getElementById("mainframe").height=ids.length*24+410; 
				        }
				        //var n = jQuery("#gridTable").getGridParam('records'); 
         		        for(i=0;i<ids.length;i++){
         		        	var data =jQuery("#gridTable").getRowData(ids[i]); 
         		        	if(data.PRODUCT_NUM<=data.KUCUN){
								$("#"+ids[i]).find("td").css("background-color", "red"); 
							}
         		        }
					},
					jsonReader: {
						root:"rows",		// 数据行（默认为：rows）
						page: "page",  	// 当前页
						total: "total",  // 总页数
						records: "records",  // 总记录数
						repeatitems : false		// 设置成false，在后台设置值的时候，可以乱序。且并非每个值都得设
					},
					prmNames:{rows:"rows",page:"page",sort:"sidx",order:"sord",search:"search"},
					pager:"#gridPager",
					caption: "设备价格台账列表"
			});
			    $("#consoleDlg").dialog({
			        autoOpen: false,      
			        modal: true,    // 设置对话框为模态（modal）对话框  
			        resizable: true,      
			        width: 700,  
			        buttons: {  // 为对话框添加按钮  
			            "关闭": function() {$("#consoleDlg").dialog("close")}
			        }  
			    }); 
				 jQuery("#gridTable").jqGrid('navGrid','#gridPager',{add:false,edit:false,del:false,search:false,refresh:false});
					jQuery("#gridTable").jqGrid('navButtonAdd','#gridPager',
								{ 	
								caption: "",                          
								onClickButton : function (){                               
								jQuery("#gridTable").jqGrid('setColumns');                           
								}
					}); 
								doResize(); 
							//	afterCompleteFunction();										
	}); 
	
	//执行大小
	function doResize() { 
		var ss = getPageSize(); 
		//alert(ss.WinH);
		
			 $("#gridTable").jqGrid('setGridHeight', ss.WinH-245);
			 $("#gridTable").jqGrid('setGridWidth', ss.WinW-30); 
			} 
		//删除 
	function deleteE(){
		var ids = $("#gridTable").jqGrid("getGridParam", "selarrrow") + "";
	    if (!ids) {
	    alert("请先选择记录!");  
	       return false;  
		} 
		if(!confirm("是否确认删除 ？")){
		   return false;
		}
		 var params = {  
			        "ids": ids
			    };  
		var actionUrl = "<%=request.getContextPath() %>/eqAction!deleteData.action?ids="+ids;  
		$.ajax({  
			  url : actionUrl,  
		      type : "post", 
		      data : params,  
		      dataType : "json",  
		      cache : false,  
		      error : function(textStatus, errorThrown) {  
		          alert("系统ajax交互错误: " + textStatus.value);  
		      },  
		      success : function(data, textStatus) {
		      	if(data.result=='success'){
		      		alert("删除成功！");       
		      		gridSearch();    
		      	}else{
		      		alert("删除失败！");
		      	}
		    }  
		});
	}
	
	 //查看
		function chakan(){
			var ids= $("#gridTable").jqGrid("getGridParam", "selarrrow") + "";
			if (!ids) {
			    alert("请先选择记录!");  
			    return false;  
			}
			if(ids.indexOf(",")!=-1){
				  alert("只能选择一条记录!");  
			        return false; 
			}
			var row = jQuery("#gridTable").jqGrid('getRowData',ids);//获取选中行.
			var id = row.ID;//获取选中行的id属性
			var toUrl = '<%=request.getContextPath() %>/eqAction!toUpdateOrView.action?jcb_id='+row.jcb_id+'&flag=0&id='+id+'&temp='+Math.round(Math.random()*10000);
			$.dialog({
		        title: '设备价格台账查看',
		        content: 'url:'+ toUrl,
		        okVal: false,//确定按钮文字
		        cancelVal: false,//取消按钮文字
		        min: true, //是否显示最小化按钮
		        max: false,//是否显示最大化按钮
		        fixed: false,//开启静止定位
		        lock: true,//开启锁屏
		        focus: true,//弹出窗口后是否自动获取焦点（4.2.0新增）
		        time: null,//设置对话框显示时间
		        resize: true,//是否允许用户调节尺寸
		        drag: true,//是否允许用户拖动位置
		        cache: false,//是否缓存iframe方式加载的窗口内容页
		        width: '950px',
		        height: 600
			});
			}
		//修改
		function updateE(){
			var ids= $("#gridTable").jqGrid("getGridParam", "selarrrow") + "";
			if (!ids) {
			    alert("请先选择记录!");  
			    return false;  
			}
			if(ids.indexOf(",")!=-1){
				  alert("只能选择一条记录!");  
			        return false; 
			}
			var row = jQuery("#gridTable").jqGrid('getRowData',ids);//获取选中行.
			var id = row.ID;//获取选中行的id属性.
			$.dialog({
		        title: '设备价格台账修改',
		        content: 'url:'+ '<%=request.getContextPath() %>/eqAction!toUpdateOrView.action?flag=1&id='+id+'&temp='+Math.round(Math.random()*10000),
		        okVal: false,//确定按钮文字
		        cancelVal: false,//取消按钮文字
		        min: true, //是否显示最小化按钮
		        max: false,//是否显示最大化按钮
		        fixed: false,//开启静止定位
		        lock: true,//开启锁屏
		        focus: true,//弹出窗口后是否自动获取焦点（4.2.0新增）
		        time: null,//设置对话框显示时间
		        resize: true,//是否允许用户调节尺寸
		        drag: true,//是否允许用户拖动位置
		        cache: false,//是否缓存iframe方式加载的窗口内容页
		        width: '950px',
		        height:  600
			});
		}
		
			//添加
		function addE(){ 
			$.dialog({
		        title: '设备价格台账添加',
		        content: 'url:<%=request.getContextPath() %>/view/equipment_add.jsp',
		        okVal: false,//确定按钮文字
		        cancelVal: false,//取消按钮文字
		        min: true, //是否显示最小化按钮
		        max: false,//是否显示最大化按钮
		        fixed: false,//开启静止定位
		        lock: true,//开启锁屏
		        focus: true,//弹出窗口后是否自动获取焦点（4.2.0新增）
		        time: null,//设置对话框显示时间
		        resize: true,//是否允许用户调节尺寸
		        drag: true,//是否允许用户拖动位置
		        cache: false,//是否缓存iframe方式加载的窗口内容页
		        width: '950px',
		        height: 600
			});
 		}
	        
	      //页面上的刷新按钮
			function shuaXin(){
				reset();
				gridSearch();
			}
	   
	
	

		//导出
		function expExcel(){
			var colNames = jQuery("#gridTable").jqGrid('getGridParam','colNames');
			var titleNames ="";
			var fieldsNames ="";
			for(var i=2;i<colNames.length;i++){
			titleNames+=colNames[i]+",";
			} 
			titleNames = encodeURIComponent(titleNames);
			var colModel = jQuery("#gridTable").jqGrid('getGridParam','colModel');
			for(var i=2;i<colModel.length;i++){
			fieldsNames+=colModel[i]["name"]+",";
			} 
			fieldsNames = encodeURIComponent(fieldsNames);
			$('#form1').attr("action","<%=request.getContextPath() %>/eqAction!exportExcel.action?titleNames="+titleNames+"&fieldsNames="+fieldsNames);
			$('#form1').submit();
		}
		
		//导入
		function impExcel(){
			var type="eqAction!importExcelData.action";
			var sURL="file_importecxel.jsp?type="+type;
	   		window.showModalDialog(sURL,"","dialogWidth=400px;dialogHeight=200px;dialogLeft:400xp;dialogTop:100xp");
	    	gridSearch();
		}

	
		
		//查询
		function gridSearch(){
			var EQU_NAME = $.trim(jQuery("#EQU_NAME").val());
            var EQU_NO = $.trim(jQuery("#EQU_NO").val()); 
            var EQU_C_NO = $.trim(jQuery("#EQU_C_NO").val());
            var PRODUCT_TH = jQuery("#PRODUCT_TH").val();
            var MANUFACTURERS = jQuery("#MANUFACTURERS").val();
            var LOCATION = jQuery("#LOCATION").val();
            var RUKU_TYPE = jQuery("#RUKU_TYPE").val(); 
            var DANJH = $.trim(jQuery("#DANJH").val());
            var XHP_TYPE = $.trim(jQuery("#XHP_TYPE").val());
            var params = {  
                        "EQU_NAME" : encodeURIComponent(EQU_NAME),                           
                        "EQU_NO" : encodeURIComponent(EQU_NO),
                        "EQU_C_NO" : encodeURIComponent(EQU_C_NO),
                        "PRODUCT_TH" : encodeURIComponent(PRODUCT_TH),
                        "MANUFACTURERS" : encodeURIComponent(MANUFACTURERS),
                        "LOCATION" : encodeURIComponent(LOCATION),                           
                        "RUKU_TYPE" : encodeURIComponent(RUKU_TYPE),
                        "DANJH" : encodeURIComponent(DANJH),
                        "XHP_TYPE" : encodeURIComponent(XHP_TYPE)
                        }
            var postData = $("#gridTable").jqGrid("getGridParam", "postData");
            $.extend(postData, params);
			jQuery("#gridTable").jqGrid('setGridParam',
			{
				url:'<%=request.getContextPath() %>/eqAction!queryDataList.action'
			}).trigger("reloadGrid", [{page:1}]);
        } 
       
		//刷新
		function refreshIt(){
			reset();
			gridSearch();
		}
		//清空
		function reset(){
			jQuery("#EQU_NAME").val("");
			jQuery("#EQU_NO").val("");
			jQuery("#EQU_C_NO").val("");
			jQuery("#PRODUCT_TH").val("");	
			jQuery("#MANUFACTURERS").val("");
			jQuery("#LOCATION").val("");
			jQuery("#RUKU_TYPE").val("请选择");
			jQuery("#DANJH").val("");
			jQuery("#XHP_TYPE").val("请选择");
		}
		
		function Recorder(){
			
		}
	      
	</script>	
	</head>
	<body>
	<form action="" method="post" id="form1">
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
			<tr>
		   		<td>
			 		<table width="100%" border="0" cellspacing="0" cellpadding="0" class="font12Black_B">
			   		<tr>
			        	<td width="8%" height="35">设备名称：</td>
			        	<td width="12%"><input type="text" name="EQU_NAME" id="EQU_NAME" class="search_InputText" style="width:99%;"/></td>
			        	<td width="8%" height="35" align="right">设备编号：</td>
			        	<td width="12%"><input type="text" name="EQU_NO" id="EQU_NO"  class="search_InputText" style="width:99%;" /> </td>
			        	<td width="8%" height="35" align="right">出厂编号：</td>
			       	 	<td width="12%"><input type="text" name="EQU_C_NO" id="EQU_C_NO"  class="search_InputText" style="width:99%;" /></td>
			       	 	<td width="15%" align="center"><input type="button" name="button" id="button" value="查询" onclick="gridSearch()" class="search_Btn" />
			      			&nbsp;<input type="reset" name="button2" id="button2" value="清空" onclick="reset()" class="search_Btn" />
			      		</td>
			      	</tr>
			      </table>
			      <div id="panel" style="display:none;">
			      <table width="100%" border="0" cellspacing="0" cellpadding="0" class="font12Black_B">
			      	<tr>
			      		<td width="8%" height="35">产品图号：</td>
			        	<td width="12%"><input type="text" name="PRODUCT_TH" id="PRODUCT_TH" class="search_InputText" style="width:99%;"/></td>
			        	<td width="8%" height="35" align="right">存放位置：</td>
			        	<td width="12%">
			        	<input type="text" name="LOCATION" id="LOCATION"  class="search_InputText" style="width:99%;" />
			       	 	<td width="8%" height="35" align="right">单据号：</td>
			       	 	<td width="12%"><input type="text" name="DANJH" id="DANJH"  class="search_InputText" style="width:99%;" /></td>
			       	 	<td width="15%" align="center">
			      		</td>
			      	</tr>
			      	<tr>
			      		  <td width="8%" height="35">入库类型：</td>
			        	<td width="12%">
			        		<select id="RUKU_TYPE" class='fselect' name="RUKU_TYPE"  style="width:124px;"  class='search_InputText'  >
			 			      <option value="">请选择</option>
			 			      <option value="类型1">类型1</option>
			 			      <option value="类型2">类型2</option>
			 			    </select>
			        	</td>
			        	<td width="8%" height="35">消耗品类型：</td>
			        	<td width="12%">
							<select id="XHP_TYPE" class='fselect' name="XHP_TYPE"  style="width:162px;"  class='search_InputText'  >
			 			      <option value="">请选择</option>
			 			      <option value="设备附件类">设备附件类</option>
			 			      <option value="传感器类">传感器类</option>
						      <option value="管线类">管线类</option>
						      <option value="工具类">工具类</option>
						      <option value="其它类">其它类</option>
			 			    </select>
			 			</td>
			       	 	<td width="8%" height="35" align="right">生产厂商：</td>
			       	 	<td width="12%"><input type="text" name="MANUFACTURERS" id="MANUFACTURERS"  class="search_InputText" style="width:99%;" /></td>
			       	 	<td width="8%" height="35"></td>
			        	<td width="12%">
			       	 	<td width="15%" align="center">
			      		</td>
			      	</tr>
			    </table>
			    </div>	   
		  		</td>
		 	  </tr>
		      <tr>
                <td align="right" height="9" class="sclinebotBg"></td>
	          </tr>
		      <tr>
			    <td width="92%" align="right"><div class="btnStatus" id="flip"></div></td>
			    <td width="8%">&nbsp;</td>
			  </tr>
			</table>
			<table style="width: 100%;" class="tableCont">
				<tr>
					<td height="25" valign="top">
		         	<input id="add"    type='button' value='添 加' onclick="addE()" class='button_b' />
					<input id="update" type='button' value='修 改' onclick='updateE()' class='button_b' />
					<input id="delete" type='button' value='删 除' onclick='deleteE()' class='button_b' />
					<input id="search" type='button' value='查 看' onclick='chakan();' class='button_b' />
					<input id="importE" type='button' value='导入' onclick='impExcel()' class='button_b' />
					<input id="exportE" type='button' value='导出' onclick='expExcel()' class='button_b' />
				</tr>
				<tr>
					<td colspan="4" style="padding-top:8px;">
						<table id="gridTable"></table>
						<div id="gridPager"></div>
					</td>
				</tr>
		   </table>
	</form>
	</body>
</html>
